import TreeCesiumData from "./layer_tree_data";
import LayerManager from "@/plugins/mev/layer/LayerManager";
class ImageTilesData extends TreeCesiumData {
    constructor(data, viewer) {
        super(data, viewer);
        /* this._imagelayer = null;*/
        this._data = data;
        this._viewer = viewer;

        //通过路径生成的影像对象
        this._DataObject = null;
        //影像数据的范围
        this._Scope = JSON.parse(JavaContext.getImageTilesInfo(data.path));
    }

    show() {
        let that = this;
        this._data.path;
        let str = this._data.path;
        let index = str.lastIndexOf("/");
        str = str.substring(index + 1, str.length);
        if (this._DataObject == null) {
            let url = this._data.path;
            url = url.replace(str, "");
            if(!that._Scope.minx || !that._Scope.miny || !that._Scope.maxx || !that._Scope.maxy){
                return;
            }
            let west = parseFloat(that._Scope.minx);
            let south = parseFloat(that._Scope.miny);
            let east = parseFloat(that._Scope.maxx);
            let north = parseFloat(that._Scope.maxy);
            this._DataObject = new Cesium.ImageryLayer(
                new Cesium.UrlTemplateImageryProvider({
                    /*   url: Environment.getDataBasePath() + this._data.path*/
                    url: url + "{z}/{x}/{y}",
                    rectangle: Cesium.Rectangle.fromDegrees(west, south, east, north)
                })
            );
        }
        if (!this._viewer.imageryLayers.contains(this._DataObject)) {
            this._viewer.imageryLayers.add(this._DataObject,this._data.index+1);
        }
        this._DataObject.show = true;
        /* this.flyTo(that._DataObject);*/
    }

    close() {
        if (this._DataObject) {
            if (this._viewer.imageryLayers.contains(this._DataObject)) {
                this._viewer.imageryLayers.remove(this._DataObject, true);
            }
            this._DataObject = null;
        }
    }

    setProperties(props) {}
}

export default ImageTilesData;
